#include "registerdialog.h"
#include "ui_registerdialog.h"
#include <QFile>
#include <QMessageBox>

registerDialog::registerDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::registerDialog)
{
    ui->setupUi(this);
}

registerDialog::~registerDialog()
{
    delete ui;
}

void registerDialog::on_pushButton_clicked()
{
    QString username = ui->username_QLineEdit->text();
    QString password = ui->password_QLineEdit->text();
    if(username.length() == 0 || password.length() == 0)
    {
        QMessageBox::warning(this,"提示","\n账号密码不能为空!     \n");

        return;
    }

    QFile file("C:/Users/NAIM/Desktop/account.txt");

    file.open(QIODevice::ReadOnly);
    while(!file.QIODevice::atEnd())
    {
        QString info = file.readLine();
        QStringList list =  info.split("@");
        if(username == list.at(0))
        {
            QMessageBox::warning(this,"提示","账号重复!");
            return;
        }
    }

    file.close();

    file.open(QIODevice::WriteOnly | QIODevice::Append);

    QString info = username + "@" + password + "\n";
    file.write(info.toUtf8());
    file.close();

    QMessageBox::information(this,"提示","注册成功!");
}
